#include "joincommand.h"
#include <iostream>
using std::cout;
using std::endl;

#include <sstream>
using std::ostringstream;

#include <Poco/StringTokenizer.h>
using Poco::StringTokenizer;

#include <Poco/DOM/Comment.h>
#include <Poco/DOM/Element.h>
#include <Poco/DOM/DOMWriter.h>
using Poco::XML::Comment;
using Poco::XML::Element;
using Poco::XML::DOMWriter;

namespace Commands{
	const string JoinCommand::NAME = "join";

	JoinCommand::JoinCommand()
	{}
	
	JoinCommand::~JoinCommand()
	{}
	
	void JoinCommand::execute()
	{
		setResult("OK");
	}
	
	string JoinCommand::name()
	{
		return string(JoinCommand::NAME);
	}
			
	string JoinCommand::repr(){
		ostringstream out;
		DOMWriter w;
		w.writeNode(out, toXML());
		return out.str();

	}
			
	CommandCreator JoinCommand::creator(){
		return JoinCommand::makeCommand;
	}
	
	Command* JoinCommand::makeCommand(string r, void*)
	{
		cout << "JoinCommand :: Making The Command from its representational string" << endl;
		// Maybe do something with this when we put extra info in the command, otherwise not necessary if we strip the command-tags...
		//DOMParser parser;
		//Document* doc = parser.parseString(r);
		return new JoinCommand();

	}

	Document* JoinCommand::toXML(Document*)
	{
		Document* doc = new Document();

		Comment* join = doc->createComment("Hi, I'd like to join you!");
		doc->appendChild(join);

		return Command::toXML(doc);
	}
}

